package tenantchannellogic

import (
	"context"
	model "gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/model/tenant/channel"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/pkg/xerrors"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/rpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpiInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpiInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpiInfoLogic {
	return &UpiInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UpiInfoLogic) UpiInfo(in *rpc.UpiInfoRequest) (*rpc.UpiInfoResponse, error) {
	var CommonResp rpc.CommonResp

	upiModel := model.NewTenantChannelUpiModel(l.ctx, l.svcCtx.Db)
	upi, err := upiModel.GetUpiById(in.Id)
	if err != nil {
		CommonResp.Code = xerrors.DBError
		CommonResp.Message = "Database operation error"
		return &rpc.UpiInfoResponse{
			CommonResp: &CommonResp,
		}, err
	}

	return &rpc.UpiInfoResponse{
		Id:           upi.ID,
		CreatedAt:    upi.CreatedAt,
		UpdatedAt:    upi.UpdatedAt,
		Upi:          upi.Upi,
		MinAmount:    upi.MinAmount,
		MaxAmount:    upi.MaxAmount,
		DailyTimes:   upi.DailyTimes,
		DailyAmount:  upi.DailyAmount,
		RemainTimes:  upi.RemainTimes,
		RemainAmount: upi.RemainAmount,
		VisionLevel:  upi.VisionLevel,
		IsDisplay:    upi.IsDisplay,
		CommonResp:   &CommonResp,
	}, nil
}
